


    import * as React from 'react';
    import * as ReactDOM from 'react-dom';


    var $input = require("./input.js");
    var INPUT = $input.INPUT;
    /*input label插件*/
    var INPUT_LABEL = $input.INPUT_LABEL;
    /*textarea插件*/
    var TEXTAREA = $input.TEXTAREA;
    /*验证插件*/
    // var SELECT = require("./select.js").SELECT;
    var SELECT = require("./select-table.js").SELECT;
    var LIST_SELECT = require("./list-select-table.js").LIST_SELECT;
    var CALENDAR = require("./calendar");

    var RADIO = require("./radio.js").RADIO;
    var CHECKBOX = require("./radio.js").CHECKBOX;

    var init = function (Action, Store) {


        var IN = React.createClass({
            getDefaultProps: function () {
                return {
                    cssLength: 1,
                    css: {
                        0: "",
                        1: "one",
                        2: "two",
                        3: "three",
                        4: "four"
                    },
                    isClear:true,
                    placeholder: ""
                };
            },
            componentWillMount: function () {

            },
            onStatusChange: function () {
                //console.error("永远不会执行")
            },
            componentDidMount: function () {
                this.unsubscribe = Store.listen(this.onStatusChange);
            },
            componentWillUnmount: function () {
                this.unsubscribe();
            },
            handleBlur: function (value) {
                //console.log("form input失去焦点而已 啥事都不做");
            },
            setFormValue: function (item) {
                //console.log("设置值：" + JSON.stringify(item));
                if (typeof(item.name) == "string") {
                    Action.setSearchParam(item.name, item.value);
                } else if (item.name instanceof Array) {
                    for (var i = 0; i < item.name.length; i++) {
                        Action.setSearchParam(item.name[i], item.value[i]);
                        //console.log("设置表格值：" + item.name[i] + "   " + item.value[i])
                    }
                }

            },
            render: function () {
                //console.log("9999999999999999999999999" + this.props.param.name);
                var cssLength = "from-in-area " + this.props.css[this.props.param.csslength];
                var defaultValue = this.props.param.defaultValue ? this.props.param.defaultValue : "";
                return (
                    <div className={cssLength}>
                        {(() => {
                            switch (this.props.param.type.toLocaleUpperCase()) {
                                case "INPUT":
                                    return (
                                        <INPUT placeholder={this.props.param.placeholder} name={this.props.param.name}
                                               setFormValue={this.setFormValue} handleBlur={this.handleBlur} defaultValue={defaultValue}/>
                                    )
                                case "INPUT_LABEL":
                                    return (
                                        <INPUT_LABEL placeholder={this.props.param.placeholder} name={this.props.param.name}
                                                     setFormValue={this.setFormValue} handleBlur={this.handleBlur}
                                                     subTitle={this.props.param.subTitle} defaultValue={defaultValue}/>
                                    )
                                case "TEXTAREA":
                                    return (
                                        <TEXTAREA placeholder={this.props.param.placeholder} name={this.props.param.name}
                                                  setFormValue={this.setFormValue} handleBlur={this.handleBlur} defaultValue=""/>
                                    )
                                 case "SELECT":
                                    return (
                                        <SELECT isClear={this.props.isClear}  defaultShowName={this.props.param.defaultShowName} placeholder={this.props.param.placeholder} name={this.props.param.name}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} isAuto={this.props.param.isAuto===false?false:true} />
                                    )
                                case "SELECT_BY_PARAM":
                                    return (
                                            <SELECT isClear={this.props.isClear} defaultShowName={this.props.param.defaultShowName} placeholder={this.props.param.placeholder} name={this.props.param.name} changeSelfState={this.changeSelfState}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} url={this.props.param.url}
                                                searchParam={this.props.param.searchParam} isAuto={this.props.param.isAuto} reFreshNum={this.props.param.reFreshNum} />
                                        )
                                case "RADIO":
                                    return (
                                            <RADIO placeholder={this.props.param.placeholder} name={this.props.param.name} changeSelfState={this.changeSelfState}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} url={this.props.param.url}
                                                searchParam={this.props.param.searchParam}/>
                                        )
                                case "CHECKBOX":
                                    return (
                                            <CHECKBOX placeholder={this.props.param.placeholder} name={this.props.param.name} changeSelfState={this.changeSelfState}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey} url={this.props.param.url}
                                                searchParam={this.props.param.searchParam}/>
                                        )
                                case "LIST_SELECT":
                                    return (
                                        <LIST_SELECT isClear={this.props.isClear} defaultShowName={this.props.param.defaultShowName} placeholder={this.props.param.placeholder} url={this.props.param.url || ''} name={this.props.param.name}
                                                setFormValue={this.setFormValue} handleBlur={this.handleBlur} keyName={ this.props.param.keyName}
                                                defaultValue={defaultValue} valuekey={this.props.param.valuekey}/>
                                    )
                                case "UPIMAGE":
                                    return (
                                        <UPIMGAE placeholder={this.props.param.placeholder} name={this.props.param.name}
                                                 setFormValue={this.setFormValue} handleBlur={this.handleBlur} defaultValue={defaultValue}/>
                                    )
                                case "CALENDAR":
                                    return (
                                        <CALENDAR placeholder={this.props.param.placeholder} name={this.props.param.name}
                                                  setFormValue={this.setFormValue} handleBlur={this.handleBlur} defaultValue={defaultValue}/>
                                    )
                                default:
                                    return (
                                        <INPUT placeholder={this.props.param.placeholder} name={this.props.param.name}
                                               setFormValue={this.setFormValue} handleBlur={this.handleBlur} defaultValue={defaultValue}/>
                                    )
                            }
                        })()}
                    </div>
                )
            }

        })


        return {
            IN: IN
        }

    }


    module.exports =  {
        init:init
    };

